<script setup>
import { defineOptions } from "vue";
import { reactive } from "vue";

defineOptions({
  name: "classification",
});

// do not use same name with ref
const form = reactive({
  name: "",
  region: "",
  date1: "",
  date2: "",
  delivery: false,
  type: [],
  resource: "",
  desc: "",
});

const handleEdit = (index, row) => {
  console.log(index, row);
};
const handleDelete = (index, row) => {
  console.log(index, row);
};

const tableData = [
  {
    date: "儿童图书",
    num: "311",
    address: "No. 189, Grove St, Los Angeles",
  },
  {
    date: "儿童图书",
    num: "123",
    address: "No. 189, Grove St, Los Angeles",
  },
  {
    date: "儿童图书",
    num: "31",
    address: "No. 189, Grove St, Los Angeles",
  },
  {
    date: "儿童图书",
    num: "4",
    // address: "No. 189, Grove St, Los Angeles",
  },
];
</script>

<template>
  <div class="fenlei">
    <el-form inline class="form center">
      <el-form-item label="图书分类管理">
        <el-input v-model="form.name" placeholder="请输入..." />
      </el-form-item>
      <el-button type="primary">搜索</el-button>
      <el-button type="info">重置</el-button>
    </el-form>
    <el-button type="primary">新增</el-button>

    <div class="content">
      <el-table :data="tableData" style="width: 100%">
        <el-table-column label="图书分类" width="180">
          <template #default="scope">
            <div style="display: flex; align-items: center">
              <span style="margin-left: 10px">{{ scope.row.date }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="图书分类" width="180">
          <template #default="scope">
            <div style="display: flex; align-items: center">
              <span style="margin-left: 10px">{{ scope.row.num }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template #default="scope">
            <el-button size="small" @click="handleEdit(scope.$index, scope.row)"
              >编辑</el-button
            >
            <el-button
              size="small"
              type="danger"
              @click="handleDelete(scope.$index, scope.row)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="footer">
      <div class="demo-pagination-block">
        <el-pagination
          v-model:current-page="currentPage4"
          v-model:page-size="pageSize4"
          :page-sizes="[100, 200, 300, 400]"
          :small="small"
          :disabled="disabled"
          :background="background"
          layout="total, sizes, prev, pager, next, jumper"
          :total="400"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>
  </div>
</template>

<style scoped>
.center {
  display: flex;
}
.el-form-item {
  width: 500px;
}
.footer {
  margin-top: 20px;
  display: flex;
  justify-content: end;
}
</style>
